package com.chen.blue.converter.system;

import com.chen.blue.domain.dto.system.DeptDto;
import com.chen.blue.domain.dto.system.RoleDto;
import com.chen.blue.domain.dto.system.update.DeptDtoEdit;
import com.chen.blue.domain.dto.system.update.RoleDtoEdit;
import com.chen.blue.domain.model.system.DeptModel;
import com.chen.blue.domain.model.system.RoleModel;
import com.chen.blue.domain.vo.system.DeptVo;
import com.chen.blue.domain.vo.system.RoleVo;
import org.springframework.cglib.beans.BeanCopier;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * Created By CLT On 2024/4/29.
 */
@SuppressWarnings("all")
public abstract class DeptConverter {

    private static final BeanCopier modelToVo = BeanCopier.create(DeptModel.class, DeptVo.class, false);
    private static final BeanCopier dtoToModel = BeanCopier.create(DeptDto.class, DeptModel.class, false);
    private static final BeanCopier dtoEditToModel = BeanCopier.create(DeptDtoEdit.class, DeptModel.class, false);


    /**
     * model->vo
     *
     * @param model
     * @return
     */
    public static DeptVo modelToVo(DeptModel model) {
        if (Objects.isNull(model)) {
            return null;
        }
        DeptVo deptVo = new DeptVo();
        modelToVo.copy(model, deptVo, null);
        return deptVo;
    }

    /**
     * model->volist
     *
     * @param modelList
     * @return
     */
    public static List<DeptVo> modelToVoList(List<DeptModel> modelList) {
        if (modelList.size() == 0) {
            return null;
        }

        List<DeptVo> deptVoList = new ArrayList<>();
        for (DeptModel deptModel : modelList) {
            deptVoList.add(modelToVo(deptModel));
        }

        return deptVoList;

    }

    /**
     * dto->model
     *
     * @param userDto
     * @return
     */
    public static DeptModel dtoToModel(DeptDto deptDto) {

        if (Objects.isNull(deptDto)) {
            return null;
        }

        DeptModel deptModel = new DeptModel();
        dtoToModel.copy(deptDto, deptModel, null);
        return deptModel;

    }

    /**
     * editDto->model
     *
     * @param userDtoEdit
     * @return
     */
    public static DeptModel dtoEditToModel(DeptDtoEdit deptDtoEdit) {

        if (Objects.isNull(deptDtoEdit)) {
            return null;
        }

        DeptModel deptModel = new DeptModel();
        dtoEditToModel.copy(deptDtoEdit, deptModel, null);
        return deptModel;

    }


}
